import {
    mapMutations,
    mapActions
} from 'vuex'

let myOptions = []

function MyPlugin(options) {
    myOptions = options
    return MyPlugin
}
MyPlugin.install = function(Vue) {
    Vue.mixin({
        created() {
            myOptions.forEach(name => {
                // 判断当前组件名
                if (this.$options.name === name) {
                    // 根据vuex去改变数据
                    this.getBranchCascade()
                    this.getDepartmentByAction()
                }
            })
        },
        methods: {
            ...mapMutations(['addTag']),
            ...mapActions(['getBranchCascade', 'getDepartmentByAction']),

            /**
             * 页面跳转
             * @param {String} name 路由name 
             * @param {string} title 路由title
             * @param {Object} params params参数 
             */
            $_changePage(name, title, params = {}) {
                const route = {
                    name: name,
                    params: params,
                    meta: {
                        title: title
                    }
                }
                this.addTag({
                    route: route,
                    type: 'push'
                })
                this.$router.push(route)
            },
        }
    })
}
export default MyPlugin